package com.delivery.www.servlet;

import com.delivery.www.po.Coupon;
import com.delivery.www.po.Seller;
import com.delivery.www.service.ServiceImpl.CouponServiceImpl;

import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import static com.delivery.www.servlet.AddCoupon.addCoupon;
import static com.delivery.www.servlet.SellerStorePage.storePage;

public class CouponPage {
    public static void couponPage(int storeId, Seller seller) {
        CouponServiceImpl couponService = new CouponServiceImpl();
        List<Coupon> coupons = couponService.getCoupon(storeId);
        Scanner scanner = new Scanner(System.in);
        System.out.println("店铺已有优惠券");
        for (Coupon coupon : coupons) {
            System.out.println("================================");
            System.out.println("抵用券id:" + coupon.getCouponId());
            System.out.println("抵用券金额:" + coupon.getValue());
            System.out.println("抵用券最低消费:" + coupon.getMin());
            System.out.println("================================");
        }
        System.out.println("请输入您要进行的操作");
        System.out.println("1.删除抵用券");
        System.out.println("2.增加抵用券");
        System.out.println("3.返回");
        int i = scanner.nextInt();
        while (i != 1 && i != 2 && i != 3) {
            System.out.println("输入错误！请重新输入");
            i = scanner.nextInt();
        }
        if (i == 1) {
            System.out.println("请输入你要删除的抵用券id");
            int i1 = scanner.nextInt();
            boolean b = couponService.deleteCoupon(i1);
            if (b) {
                System.out.println("删除成功！即将跳转");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                couponPage(storeId, seller);
            }
        }
        if (i == 2) {
            addCoupon(storeId, seller);
        }
        if (i == 3) {
            storePage(seller);
        }
    }
}
